package cn.bx.bid.service;

import cn.bx.bid.dao.UserDao;
import cn.bx.bid.entity.Page;
import cn.bx.bid.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

//M V C
@Service
@Scope("prototype")
@Transactional(readOnly = true)
public class UserService {
	public static final int PAGE_SIZE = Page.PAGE_SIZE;
	@Autowired
	private UserDao userDao;

	@Transactional(readOnly = false)
	public int add(User u) {
			return userDao.add(u);
		}

	@Transactional(readOnly = false)
	public int update(User u) {
			return userDao.update(u);
	}

	@Transactional(readOnly = false)
	public int batchDel(long[] ids) {
			return userDao.batchDel(ids);
	}

	public boolean checkUserNameRepeat(Long id, String userName) {
			return userDao.checkUserNameRepeat(id,userName)>0;
	}

	public Page<User> paging(int pageNo, int limit, String name, Date start, Date end) {
			List<User> list = userDao.search(pageNo, limit, name, start, end);
			int total = userDao.searchTotal(name, start, end);
			Page<User> p = new Page<User>(total, limit, list);
			return p;
	}

	public User get(long id) {
		return userDao.get(id);
	}

	public User login(String u,String p){return userDao.login(u,p);}

	public int del(long id){return userDao.del(id);}
}
